package com.joelaws.prototype.server.meeting;

import com.joelaws.prototype.client.meeting.MeetingType;
import com.joelaws.prototype.server.meeting.Actions.EndAction;
import com.joelaws.prototype.server.meeting.Actions.InitAction;

public class State {

	private long userOne;

	private long userTwo;

	private MeetAction currentAction;

	public State(long userOne, long userTwo) {
		this.userOne = userOne;
		this.userTwo = userTwo;
		this.currentAction = new InitAction(userOne, userTwo);
	}

	@Override
	public int hashCode() {
		int code = 17;
		code += 37 * code + new Long(userOne).hashCode();
		code += 37 * code + new Long(userTwo).hashCode();
		return code;
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof State)) {
			return false;
		}
		State other = (State) o;
		return userOne == other.userOne && userTwo == other.userTwo;
	}

	@Override
	public String toString() {
		return "userOne: " + userOne + " userTwo: " + userTwo;
	}

	public String getActionQuestion(long userID) {
		if (currentAction instanceof EndAction) {
			return "Meeting has been completed";
		} else {
			return currentAction.getActionQuestion(userID);
		}
	}

	public String[] getActionChoices(long userID) {
		return currentAction.getActionChoices(userID);

	}

	public MeetingType getMeetingType() {
		return currentAction.getMeetingType();
	}

	public void executeAction(String choice, long userID) {
		currentAction = currentAction.nextAction(choice, userID);
	}

	public boolean isCompleted() {
		return (currentAction instanceof EndAction);
	}

	public long getUserOne() {
		return userOne;
	}

	public long getUserTwo() {
		return userTwo;
	}

	public MeetAction getCurrentAction() {
		return currentAction;
	}

}
